﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using DataMappers;
using ConcreteMappersAndObjects.Mappers;
using ExaminationTT.Control;
using ConcreteMappersAndObjects.DomainObjects;

namespace ReflAndFileExplorer
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Connection conn = new Connection();
            //conn.SetInstance(".\\SQLEXPRESS");
            //conn.SetDB("ExaminationTimetablingDB");
            //conn.SetUser("sa");
            //conn.SetPw("sapass");
            //conn.SetConntStr();

            StudentsDataMapper studentsMapper = new StudentsDataMapper();
            CUnitsDataMapper cunitsMapper = new CUnitsDataMapper();
            CourseDataMapper courseMapper = new CourseDataMapper();
            SemestersDataMapper semMapper = new SemestersDataMapper();
            CUSemesterDataMapper cuSemMapper = new CUSemesterDataMapper();
            SubscriptionsDataMapper subsmapper = new SubscriptionsDataMapper();
            CourseCUDataMapper courseCuMapper = new CourseCUDataMapper();
            RegimesDataMapper regimesMapper = new RegimesDataMapper();
            ClassesDataMapper classesMapper = new ClassesDataMapper();
            RoomsDataMapper roomsMapper = new RoomsDataMapper();
            ExamsDataMapper examsMapper = new ExamsDataMapper();
            RoomExamsDataMapper roomExamsMapper = new RoomExamsDataMapper();
            TeachersDataMapper teachersMapper = new TeachersDataMapper();
            TCCUDataMapper tccusMapper = new TCCUDataMapper();
            ExamSeasonDataMapper ExamSeasonMapper = new ExamSeasonDataMapper();
            
            studentsMapper.SetSubscriptionsMapper(subsmapper);

            cunitsMapper.SetSemestersMapper(cuSemMapper);
            cunitsMapper.SetStudentsSubscritpionMapper(subsmapper);
            cunitsMapper.SetCoursesMapper(courseCuMapper);

            courseMapper.SetCourseCUDatamapper(courseCuMapper);

            semMapper.SetCUSemesterMapper(cuSemMapper);
      
            cuSemMapper.SetCUnitsMapper(cunitsMapper);
            cuSemMapper.SetSemestersMapper(semMapper);

            subsmapper.SetCUnitsMapper(cunitsMapper);
            subsmapper.SetStudentsMapper(studentsMapper);

            courseCuMapper.SetCourseDataMapper(courseMapper);
            courseCuMapper.SetCUnitDataMapper(cunitsMapper);

            regimesMapper.SetClassesMapper(classesMapper);

            classesMapper.SetRegimeMapper(regimesMapper);

            examsMapper.SetCUnitsMapper(cunitsMapper);
            examsMapper.SetRoomsMapper(roomExamsMapper);

            roomExamsMapper.SetExamsMapper(examsMapper);
            roomExamsMapper.SetRoomsMapper(roomsMapper);

            teachersMapper.SetTeacherClassCUnitMapper(tccusMapper);

            tccusMapper.SetClassesMapper(classesMapper);
            tccusMapper.SetCUnitsMapper(cunitsMapper);
            tccusMapper.SetClassesMapper(classesMapper);
            
            
            UnitOfWork.Current = new UnitOfWork(conn);

            UnitOfWork.Current.WithEntityMapper<int, Student>(typeof(Student), studentsMapper)
                .WithEntityMapper<int, CUnit>(typeof(CUnit), cunitsMapper)
                .WithEntityMapper<int, Course>(typeof(Course), courseMapper)
                .WithEntityMapper<int, Semester>(typeof(Semester), semMapper)
                .WithEntityMapper<int, Regime>(typeof(Regime), regimesMapper)
                .WithEntityMapper<int, SClass>(typeof(SClass), classesMapper)
                .WithEntityMapper<int, Teacher>(typeof(Teacher), teachersMapper)
                .WithEntityMapper<int, ExamSeason>(typeof(ExamSeason), ExamSeasonMapper)
                .WithEntityMapper<int, Room>(typeof(Room), roomsMapper)
                .WithEntityMapper<int, Exam>(typeof(Exam), examsMapper)                
                .WithEntityMapper<CUSemesterKey, CUSemester>(typeof(CUSemester), cuSemMapper)
                .WithEntityMapper<SubscriptionKey, Subscription>(typeof(Subscription), subsmapper)
                .WithEntityMapper<CourseCUKey, CourseCU>(typeof(CourseCU), courseCuMapper)
                .WithEntityMapper<TeacherClassCUnitKey, TeacherClassCUnit>(typeof(TeacherClassCUnit), tccusMapper)
                .WithEntityMapper<RoomExamKey, RoomExam>(typeof(RoomExam), roomExamsMapper);
                
            
            HostApplication app = new HostApplication();
            UnitOfWork.Current.Refresh();
            //CUnit c = cunitsMapper.GetByID(7);
            //IEnumerator<CUSemester> lst = c.Semesters.GetEnumerator() ;
            
         
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form1 f = new Form1();
            f.SetHostApplication(app);
            Application.Run(f);
        }
    }
}
